package jmine.tec.rpc.server;

import jmine.tec.rpc.common.serialization.Serializer;
import jmine.tec.rpc.server.comm.RestServiceStub;
import jmine.tec.test.Builder;
import jmine.tec.web.servlet.rest.RestService;

/**
 * Builder de ServerStub
 * 
 * @author lundberg
 * @param <S> tipo de serviço
 */
public class ServerStubBuilder<S> implements Builder<RestService> {

    private Serializer serializer;

    private Class<S> service;

    private S implementor;

    private String prefix = "prefix";

    /**
     * {@inheritDoc}
     */
    public RestService build() {
        return new RestServiceStub<S>(this.serializer, this.service, this.implementor, this.prefix);
    }

    /**
     * @param <S> tipo
     * @return ServerStubBuilder
     */
    public static <S> ServerStubBuilder<S> aServerStub() {
        return new ServerStubBuilder<S>();
    }

    /**
     * @param aSerializer the serializer to set
     * @return this
     */
    public ServerStubBuilder<S> with(Serializer aSerializer) {
        this.serializer = aSerializer;
        return this;
    }

    /**
     * @param aService the service to set
     * @return this
     */
    public ServerStubBuilder<S> with(Class<S> aService) {
        this.service = aService;
        return this;
    }

    /**
     * @param anImplementor the implementor to set
     * @return this
     */
    public ServerStubBuilder<S> with(S anImplementor) {
        this.implementor = anImplementor;
        return this;
    }

    /**
     * @param aPrefix the prefix to set
     * @return this
     */
    public ServerStubBuilder<S> withPrefix(String aPrefix) {
        this.prefix = aPrefix;
        return this;
    }
}
